<?php
header("Content-Type: application/json; charset=utf-8;");
$connect = mysqli_connect('localhost', 'root', 'root', '24mysql');
if(!$connect){
    echo json_encode([
        'code' => 0,
        'msg' => '数据库连接失败',
        'data' => null
    ]);
}
$sql = "select d.name,count(*) as total  from emp e join dept d  on e.dapt_id=d.id group by e.dapt_id";
$query = mysqli_query($connect, $sql);
$result = mysqli_fetch_all($query,MYSQLI_ASSOC);
$xData = [];
$yData = [];
foreach ($result as $val){
    array_push($xData,$val['name']);
    array_push($yData,$val['total']);

}
echo json_encode([
    'code' => 1,
    'msg' => '数据库连接成功',
    'data' =>[
        'xData' => $xData,
        'yData' => $yData,
    ]
]);

